<script setup>
import { useRouter } from 'vue-router';
const router = useRouter();

const back = () => {
    router.back(); // 相当于go(-1)
}
const goAbout = () => {
    // router.push('/About');
    router.push('about'); // 直接通过路由名跳转也行
}
</script>

<template>
    <div>
        <RouterLink to="/Home">Home</RouterLink> |
        <RouterLink to="/About">About</RouterLink>
    </div>
    <div>
        <RouterView></RouterView>
        <button @click="$router.forward()">向前一步</button>&nbsp;
        <button @click="back">向后一步</button>&nbsp;
        <button @click="$router.push('/Home')">跳转到Home</button>&nbsp;
        <button @click="goAbout">跳转到About</button>&nbsp;
        <button @click="$router.go(-2)">回跳两步</button>&nbsp;
    </div>
</template>

<style scoped></style>